<template>
  <div>
    <div class="container">
      <div
        class="index-swiper"
        v-swiper:indexSwiper="indexSwiperOption"
        v-if="bannerData.length != 0"
      >
        <div class="swiper-wrapper">
          <div
            class="swiper-slide"
            v-for="(item, index) in bannerData"
            :key="index"
          >
            <div class="swiper-box">
              <img
                :src="$store.state.isMobile ? item.wap_thumb : item.thumb"
                alt=""
                class="banner-swiper"
                v-if="item.thumb"
              />
              <video
                width="100%"
                height="100%"
                controls="false"
                muted
                loop
                autoplay
                :src="item.video"
                v-if="item.video"
              ></video>
              <div
                class="text-box animated fadeInUp"
                v-show="index == aniIndex"
              >
                <p
                  class="info"
                  :style="{
                    color: item.desc_color,
                    fontSize: item.desc_size + 'rem',
                  }"
                >
                  {{ item.desc }}
                </p>
                <p
                  class="title"
                  :style="{
                    color: item.title_color,
                    fontSize: item.title_size + 'rem',
                  }"
                >
                  {{ item.title }}
                </p>
              </div>
            </div>
          </div>
        </div>
        <div class="swiper-pagination"></div>
      </div>
      <div class="c_content">
        <el-row style="margin-top: 56rem">
          <el-col :span="24" v-for="item in indexData" :key="item.id">
            <div class="c_full">
              <img class="c_full_img" :src="item.scene" alt="" />
              <div class="c_full_view">
                <div class="c_full_f1">{{ item.title }}</div>
                <div class="c_full_f2">{{ item.info }}</div>
                <div class="c_full_f3">
                  {{ item.features }}
                </div>
                <div
                  class="c_see_detail"
                  @click="
                    $router.push({
                      path: $i18n.path('productDetail/' + item.id),
                    })
                  "
                >
                  <img class="c_baijt" src="~/assets/images/c_bjt.png" alt="" />
                  <span class="c_full_f4">{{ $t("查看详情") }}</span>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <div class="container_mobile">
      <div
        class="index-swiper"
        v-swiper:indexSwiper="indexSwiperOption"
        v-if="bannerData.length != 0"
      >
        <div class="swiper-wrapper">
          <div
            class="swiper-slide"
            v-for="(item, index) in bannerData"
            :key="index"
          >
            <div class="swiper-box">
              <img
                :src="$store.state.isMobile ? item.wap_thumb : item.thumb"
                alt=""
                class="banner-swiper"
                v-if="item.thumb"
              />
              <video
                width="100%"
                height="100%"
                controls="false"
                muted
                loop
                autoplay
                :src="item.video"
                v-if="item.video"
              ></video>
              <div
                class="text-box animated fadeInUp"
                v-show="index == aniIndex"
              >
                <p
                  class="info"
                  :style="{
                    color: item.desc_color,
                    fontSize: item.desc_size + 'rem',
                  }"
                >
                  {{ item.desc }}
                </p>
                <p
                  class="title"
                  :style="{
                    color: item.title_color,
                    fontSize: item.title_size + 'rem',
                  }"
                >
                  {{ item.title }}
                </p>
              </div>
            </div>
          </div>
        </div>
        <div class="swiper-pagination"></div>
      </div>
      <div class="c_content">
        <el-row style="margin-top: 10px">
          <el-col :span="24" v-for="item in indexData" :key="item.id">
            <div class="c_full">
              <img class="c_full_img" :src="item.scene" alt="" />
              <div class="c_full_view">
                <div class="c_full_f1">{{ item.title }}</div>
                <div class="c_full_f2">{{ item.info }}</div>
                <div class="c_full_f3">
                  {{ item.features }}
                </div>
                <div
                  class="c_see_detail"
                  @click="
                    $router.push({
                      path: $i18n.path('productDetail/' + item.id),
                    })
                  "
                >
                  <span class="c_full_f4">{{ $t("查看详情") }}</span>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      indexSwiperOption: {
        //顶部轮播图
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
          type: "bullets",
        },
        loop: false,
        autoplay: {
          delay: 5000,
          stopOnLastSlide: false,
          disableOnInteraction: false,
        },
        slidesPerView: 1,
        spaceBetween: 0,
        speed: 800,
        on: {
          slideChangeTransitionEnd: function () {
            // console.log(this.realIndex, "this");
            that.aniIndex =
              this.activeIndex > that.bannerData.length ? 0 : this.realIndex;
          },
        },
      },
      aniIndex: 0,
    };
  },
  async asyncData({ $indexApi, params }) {
    const bannerData = await $indexApi.getBannerData({ position: "search" });
    const res = await $indexApi.getSearch({
      keyword: params.id,
    });
    // console.log(bannerData.data);

    return {
      indexData: res.data,
      bannerData: bannerData.data,
    };
  },
};
</script>

<style lang="less" scoped>
@media (min-width: 900px) {
  .container_mobile {
    display: none;
  }
  .container {
    display: block;
    .index-swiper {
      width: 100%;

      :deep(.swiper-pagination-bullet) {
        width: 120rem;
        height: 3rem;
        border-radius: 2rem;
        background: #848e94;
        margin: 0 49rem;
      }
      :deep(.swiper-pagination-bullet-active) {
        background: #fff;
      }
      .swiper-pagination {
        width: 100%;
        bottom: 45rem;
      }

      .swiper-box {
        width: 100%;
        height: 560rem;
        overflow: hidden;
        position: relative;

        .banner-swiper {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
        .text-box {
          width: 100%;
          position: absolute;
          text-align: center;
          top: 40%;
          .info {
            font-size: 30rem;
            font-family: Source Han Sans CN;
            font-weight: 300;
            color: #333333;
            margin: 0;
          }
          .title {
            font-size: 60rem;
            font-family: Source Han Sans CN;
            font-weight: 400;
            color: #333333;
            margin: 0;
            margin-top: 30rem;
          }
        }
      }
    }

    .c_content {
      padding: 40rem 100rem;
      background: #f2f2f2;
      .c_full {
        display: flex;
        margin-bottom: 20px;
        background: #fff;
        border-radius: 20rem;
        overflow: hidden;
        flex-direction: row-reverse;
        &:hover {
          .c_full_img {
            transform: scale(1.2);
          }
        }
        .c_full_img {
          width: 50%;
          height: 500rem;
          transition: 0.6s;
        }
        .c_full_view {
          width: 50%;
          padding: 0 150rem;
          display: flex;
          flex-direction: column;
          justify-content: center;
          .c_full_f1 {
            font-size: 24rem;
            font-family: Source Han Sans CN;
            font-weight: 300;
            color: #333333;
          }
          .c_full_f2 {
            margin-top: 20rem;
            font-size: 40rem;
            font-family: Source Han Sans CN;
            font-weight: 500;
            color: #333333;
          }
          .c_full_f3 {
            margin-top: 20rem;
            font-size: 20rem;
            font-family: Source Han Sans CN;
            font-weight: 300;
            color: #999999;
          }
          .c_see_detail {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 108rem;
            height: 40rem;
            background: #333333;
            border-radius: 4rem;
            cursor: pointer;
            margin-top: 90rem;
            transition: 0.6s;
            padding: 3rem 8rem;
            &:hover {
              background: #000;
            }
            .c_baijt {
              width: 18rem;
              height: 5rem;
              margin-right: 4rem;
            }
            .c_full_f4 {
              font-size: 14rem;
              font-family: Source Han Sans CN;
              font-weight: 400;
              color: #ffffff;
            }
          }
        }
      }
    }
  }
}
@media (max-width: 900px) {
  .container {
    display: none;
  }
  .container_mobile {
    display: block;
    .index-swiper {
      :deep(.swiper-pagination-bullet) {
        width: 21px;
        height: 1px;
        background: #606568;
        border-radius: 0px;
        margin: 0 18px;
      }
      :deep(.swiper-pagination-bullet-active) {
        background: #fff;
      }
      .swiper-pagination {
        width: 100%;
        bottom: 20px;
      }

      .swiper-box {
        height: auto;

        .banner-swiper {
          width: 100%;
          height: 550px;
          object-fit: cover;
        }
        .text-box {
          position: absolute;
          top: 20%;
          left: 0;
          right: 0;
          margin: 0 auto;
          text-align: center;
          .info {
            font-size: 26px !important;
          }
          .title {
            font-size: 21px !important;
            margin: 15px 0;
          }
        }
      }
    }

    .c_content {
      padding: 10px;
      background: #fafafa;
      .c_full {
        margin-bottom: 10px;
        padding-bottom: 10px;
        background: #fff;
        border-radius: 7px;
        .c_full_img {
          width: 100%;
          height: 183px;
          border-radius: 7px 7px 0px 0;
        }
        .c_full_view {
          padding: 0 10px;
          display: flex;
          flex-direction: column;
          justify-content: center;
          .c_full_f1 {
            font-size: 10px;
            font-family: Source Han Sans CN;
            font-weight: 300;
            color: #333333;
          }
          .c_full_f2 {
            margin-top: 10px;
            font-size: 15px;
            font-family: Source Han Sans CN;
            font-weight: 500;
            color: #333333;
          }
          .c_full_f3 {
            margin-top: 10px;
            font-size: 10px;
            font-family: Source Han Sans CN;
            font-weight: 300;
            color: #999999;
          }
          .c_see_detail {
            align-self: flex-end;
            width: 74px;
            height: 26px;
            text-align: center;
            line-height: 26px;
            background: #333333;
            border-radius: 2px;
            cursor: pointer;
            margin-top: 20px;
            .c_full_f4 {
              font-size: 12px;
              font-family: Source Han Sans CN;
              font-weight: 400;
              color: #ffffff;
            }
          }
        }
      }
    }
  }
}
</style>
